package org.summerframework.component.security.enumeration;

/**
 * 登录传输类型
 *
 * @author 石超
 * @version v1.0.0
 */
public enum LoginSecurityEnum {
    ERROR(-1, "不认识的登录", "public/error"),
    HTTP(1, "HTTP登录", "http"),
    HTTPS(2, "HTTPS登录", "https");
    private int type;//类型
    private String typeStr;        //类型描述
    private String typeCode;//类型code

    LoginSecurityEnum(int type, String typeStr, String typeCode) {
        this.type = type;
        this.typeStr = typeStr;
        this.typeCode = typeCode;
    }

    /**
     * 根据id返回类型enum
     *
     * @param type
     * @return
     */
    public static LoginSecurityEnum getLoginType(int type) {
        for (LoginSecurityEnum lt : values()) {
            if (lt.type == type) {
                return lt;
            }
        }
        return ERROR;
    }

    /**
     * 根据typeCode返回类型enum
     *
     * @param type
     * @return
     */
    public static LoginSecurityEnum getLoginByCode(String type) {
        for (LoginSecurityEnum lt : values()) {
            if (lt.typeCode.equalsIgnoreCase(type)) {
                return lt;
            }
        }
        return ERROR;
    }

    public int getType() {
        return type;
    }

    public String getTypeStr() {
        return typeStr;
    }

    public String getTypeCode() {
        return typeCode;
    }

}
